package com.googlecode.lohr.tools.test.parser;

import junit.framework.TestCase;

import com.googlecode.lingwah.ParseContext;
import com.googlecode.lingwah.ParseResults;
import com.googlecode.lingwah.Parser;
import com.googlecode.lingwah.grammars.ALFGrammar;

public class LohrParserTestCase extends TestCase {

	protected ParseResults testQualifiedName(String qn) {
		return testParser(ALFGrammar.DEFINITION.QualifiedName, qn);
	}
	protected ParseResults testParser(Parser matcher, String text) {
		ParseContext context= new ParseContext(text);
		//context.trace(LohrGrammar.DEFINITION.Identifier, false);
		ParseResults results= context.getParseResults(matcher, 0);
		
		if (!results.success())
			assertTrue("Match failed at position "+results.getError().position+":"+results.getError().errorMsg, results.success());
		
		int length= results.longestLength();
		assertEquals("Failed to match entire text", text.length(), length);
		
		return results;
	}

}
